package com.example.customviewtouch.downfresh.adapter

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.customviewtouch.downfresh.interfaces.IRefreshHeader
import com.example.customviewtouch.downfresh.interfaces.OnClickListener
import com.example.customviewtouch.downfresh.interfaces.RefreshHeaderState


class RefreshHeaderAdapter(private val mLists: List<String>) :
    RecyclerView.Adapter<RefreshViewHolder?>() {
    private var mRefreshHeader: IRefreshHeader? = null
    private val clickListener: OnClickListener = object : OnClickListener    {
        override fun onItemClick(position: Int) {

        }
    }

    companion object {
        private const val TYPE_REFRESH_HEADER = 100000 // 头部header
        private const val TYPE_NORMAL = 10001
    }


    fun setRefreshHeader(header: IRefreshHeader?) {
        if (header != null) {
            mRefreshHeader = header
        }
    }


    override fun onBindViewHolder(holder: RefreshViewHolder, position: Int) {

    }
    override fun getItemCount(): Int {
        return mLists.size
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RefreshViewHolder {
        RefreshHeaderState.STATE_REFRESHING.ordinal
        return if (viewType == TYPE_REFRESH_HEADER) {
            val view = mRefreshHeader?.getHeadView() ?: LayoutInflater.from(parent.context).inflate(com.example.customviewtouch.R.layout.normal_item, parent, false)
            RefreshViewHolder(mRefreshHeader?.getHeadView())
        } else {
            val view = LayoutInflater.from(parent.context).inflate(com.example.customviewtouch.R.layout.normal_item, parent, false)
            RefreshViewHolder(view)
        }
    }

    override fun getItemViewType(position: Int): Int {
        return if (position == 0) {
            TYPE_REFRESH_HEADER
        } else TYPE_NORMAL
    }
    
}